home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / fp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  29.7 KB  |  814 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        fp.h
  3.  
  4.      Contains:    FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FP__
  18. #define __FP__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23. #ifndef __MACTYPES__
  24. #include <MacTypes.h>
  25. #endif
  26.  
  27. /********************************************************************************
  28. *                                                                               *
  29. *    A collection of numerical functions designed to facilitate a wide          *
  30. *    range of numerical programming as required by C9X.                         *
  31. *                                                                               *
  32. *    The <fp.h> declares many functions in support of numerical programming.    *
  33. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  34. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  35. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  36. *                                                                               *
  37. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  38. *    positive and negative zero and infinity consistent with the floating-      *
  39. *    point standard.                                                            *
  40. *                                                                               *
  41. ********************************************************************************/
  42.  
  43.  
  44.  
  45. #if PRAGMA_ONCE
  46. #pragma once
  47. #endif
  48.  
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52.  
  53. #if PRAGMA_IMPORT
  54. #pragma import on
  55. #endif
  56.  
  57. #if PRAGMA_STRUCT_ALIGN
  58.     #pragma options align=mac68k
  59. #elif PRAGMA_STRUCT_PACKPUSH
  60.     #pragma pack(push, 2)
  61. #elif PRAGMA_STRUCT_PACK
  62.     #pragma pack(2)
  63. #endif
  64.  
  65. /********************************************************************************
  66. *                                                                               *
  67. *                            Efficient types                                    *
  68. *                                                                               *
  69. *    float_t         Most efficient type at least as wide as float              *
  70. *    double_t        Most efficient type at least as wide as double             *
  71. *                                                                               *
  72. *      CPU            float_t(bits)                double_t(bits)               *
  73. *    --------        -----------------            -----------------             *
  74. *    PowerPC          float(32)                    double(64)                   *
  75. *    68K              long double(80/96)           long double(80/96)           *
  76. *    x86              long double(80)              long double(80)              *
  77. *                                                                               *
  78. ********************************************************************************/
  79. #if defined(__MWERKS__) && defined(__cmath__)
  80. /* these types were already defined in MSL's math.h */
  81. #else
  82. #if TARGET_CPU_PPC
  83. typedef float                             float_t;
  84. typedef double                             double_t;
  85. #elif TARGET_CPU_68K
  86. typedef long double                     float_t;
  87. typedef long double                     double_t;
  88. #elif TARGET_CPU_X86
  89. #if NeXT
  90. typedef double                             float_t;
  91. typedef double                             double_t;
  92. #else
  93. typedef long double                     float_t;
  94. typedef long double                     double_t;
  95. #endif  /* NeXT */
  96.  
  97. #elif TARGET_CPU_MIPS
  98. typedef double                             float_t;
  99. typedef double                             double_t;
  100. #elif TARGET_CPU_ALPHA
  101. typedef double                             float_t;
  102. typedef double                             double_t;
  103. #elif TARGET_CPU_SPARC
  104. typedef double                             float_t;
  105. typedef double                             double_t;
  106. #else
  107. #error unsupported CPU
  108. #endif  /*  */
  109.  
  110.  
  111. /********************************************************************************
  112. *                                                                               *
  113. *                              Define some constants.                           *
  114. *                                                                               *
  115. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  116. *    INFINITY            IEEE 754 value of infinity.                            *
  117. *    NAN                 A generic NaN (Not A Number).                          *
  118. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  119. *                        double to decimal and back is the identity function.   *
  120. *                                                                               *
  121. ********************************************************************************/
  122.  
  123. #if TARGET_OS_UNIX
  124. #define        NAN                        sqrt(-1)
  125. #else
  126. #define      HUGE_VAL                  __inf()
  127. #define      INFINITY                  __inf()
  128. #define      NAN                       nan("255")
  129. #endif
  130.  
  131. #if TARGET_CPU_PPC
  132.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  133. #elif TARGET_CPU_68K
  134.     #define      DECIMAL_DIG              21
  135. #endif      
  136. #endif    /* __MWERKS__ && __cmath__ */
  137.  
  138. #if TARGET_OS_MAC
  139. /********************************************************************************
  140. *                                                                               *
  141. *                            Trigonometric functions                            *
  142. *                                                                               *
  143. *   acos        result is in [0,pi].                                            *
  144. *   asin        result is in [-pi/2,pi/2].                                      *
  145. *   atan        result is in [-pi/2,pi/2].                                      *
  146. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  147. *               both arguments to determine the quadrant of the computed value. *
  148. *                                                                               *
  149. ********************************************************************************/
  150. EXTERN_API_C( double_t ) cos(double_t x);
  151.  
  152. EXTERN_API_C( double_t ) sin(double_t x);
  153.  
  154. EXTERN_API_C( double_t ) tan(double_t x);
  155.  
  156. EXTERN_API_C( double_t ) acos(double_t x);
  157.  
  158. EXTERN_API_C( double_t ) asin(double_t x);
  159.  
  160. EXTERN_API_C( double_t ) atan(double_t x);
  161.  
  162. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  163.  
  164.  
  165.  
  166. /********************************************************************************
  167. *                                                                                *
  168. *                              Hyperbolic functions                             *
  169. *                                                                                *
  170. ********************************************************************************/
  171. EXTERN_API_C( double_t ) cosh(double_t x);
  172.  
  173. EXTERN_API_C( double_t ) sinh(double_t x);
  174.  
  175. EXTERN_API_C( double_t ) tanh(double_t x);
  176.  
  177. EXTERN_API_C( double_t ) acosh(double_t x);
  178.  
  179. EXTERN_API_C( double_t ) asinh(double_t x);
  180.  
  181. EXTERN_API_C( double_t ) atanh(double_t x);
  182.  
  183.  
  184.  
  185. /********************************************************************************
  186. *                                                                                *
  187. *                              Exponential functions                               *
  188. *                                                                                *
  189. *    expm1        expm1(x) = exp(x) - 1.  But, for small enough arguments,          *
  190. *                expm1(x) is expected to be more accurate than exp(x) - 1.        *
  191. *    frexp        Breaks a floating-point number into a normalized fraction       *
  192. *                and an integral power of 2.  It stores the integer in the       *
  193. *                object pointed by *exponent.                                    *
  194. *    ldexp        Multiplies a floating-point    number by an integer power of 2.    *
  195. *    log1p        log1p = log(1 + x). But, for small enough arguments,              *
  196. *                 log1p is expected to be more accurate than log(1 + x).          *
  197. *    logb        Extracts the exponent of its argument, as a signed integral        *
  198. *                  value. A subnormal argument is treated as though it were first    *
  199. *                  normalized. Thus:                                                *
  200. *                                     1   <=   x * 2^(-logb(x))   <   2             *
  201. *    modf        Returns fractional part of x as function result and returns     *
  202. *                integral part of x via iptr. Note C9X uses double not double_t.    *
  203. *    scalb        Computes x * 2^n efficently.  This is not normally done by        *
  204. *                  computing 2^n explicitly.                                         *
  205. *                                                                                *
  206. ********************************************************************************/
  207. EXTERN_API_C( double_t ) exp(double_t x);
  208.  
  209. EXTERN_API_C( double_t ) expm1(double_t x);
  210.  
  211. EXTERN_API_C( double_t ) exp2(double_t x);
  212.  
  213. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  214.  
  215. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  216.  
  217. EXTERN_API_C( double_t ) log(double_t x);
  218.  
  219. EXTERN_API_C( double_t ) log2(double_t x);
  220.  
  221. EXTERN_API_C( double_t ) log1p(double_t x);
  222.  
  223. EXTERN_API_C( double_t ) log10(double_t x);
  224.  
  225. EXTERN_API_C( double_t ) logb(double_t x);
  226.  
  227. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  228.  
  229. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  230.  
  231. EXTERN_API_C( float ) modff(float x, float *iptrf);
  232.  
  233. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  234.  
  235.  
  236.  
  237. /********************************************************************************
  238. *                                                                                *
  239. *                     Power and absolute value functions                          *
  240. *                                                                                *
  241. *    hypot        Computes the square root of the sum of the squares of its        *
  242. *                  arguments, without undue overflow or underflow.                 *
  243. *    pow            Returns x raised to the power of y.  Result is more accurate    *
  244. *                than using exp(log(x)*y).                                        *
  245. *                                                                                *
  246. ********************************************************************************/
  247. EXTERN_API_C( double_t ) fabs(double_t x);
  248.  
  249. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  250.  
  251. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  252.  
  253. EXTERN_API_C( double_t ) sqrt(double_t x);
  254.  
  255.  
  256.  
  257. /********************************************************************************
  258. *                                                                                 *
  259. *                        Gamma and Error functions                               *
  260. *                                                                                 *
  261. *     erf            The error function.                                             *
  262. *     erfc        Complementary error function.                                      *
  263. *     gamma        The gamma function.                                                *
  264. *     lgamma        Computes the base-e logarithm of the absolute value of            *
  265. *                 gamma of its argument x, for x > 0.                                *
  266. *                                                                                 *
  267. ********************************************************************************/
  268. EXTERN_API_C( double_t ) erf(double_t x);
  269.  
  270. EXTERN_API_C( double_t ) erfc(double_t x);
  271.  
  272. EXTERN_API_C( double_t ) gamma(double_t x);
  273.  
  274. EXTERN_API_C( double_t ) lgamma(double_t x);
  275.  
  276.  
  277.  
  278. /********************************************************************************
  279. *                                                                                 *
  280. *                        Nearest integer functions                                 *
  281. *                                                                                 *
  282. *     rint        Rounds its argument to an integral value in floating point         *
  283. *                  format, honoring the current rounding direction.                   *
  284. *                                                                                 *
  285. *     nearbyint    Differs from rint only in that it does not raise the inexact    *
  286. *               exception. It is the nearbyint function recommended by the        *
  287. *                  IEEE floating-point standard 854.                                  *
  288. *                                                                                 *
  289. *     rinttol        Rounds its argument to the nearest long int using the current     *
  290. *                  rounding direction.  NOTE: if the rounded value is outside        *
  291. *                the range of long int, then the result is undefined.              *
  292. *                                                                                  *
  293. *     round        Rounds the argument to the nearest integral value in floating     *
  294. *                  point format similar to the Fortran "anint" function. That is:  *
  295. *                  add half to the magnitude and chop.                             *
  296. *                                                                                 *
  297. *     roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  298. *                 NOTE: if the rounded value is outside the range of long int,    *
  299. *                  then the result is undefined.                                      *
  300. *                                                                                 *
  301. *     trunc        Computes the integral value, in floating format, nearest to        *
  302. *                 but no larger in magnitude than its argument.      NOTE: on 68K    *
  303. *                compilers when using -elems881, trunc must return an int        *
  304. *                                                                                 *
  305. ********************************************************************************/
  306. EXTERN_API_C( double_t ) ceil(double_t x);
  307.  
  308. EXTERN_API_C( double_t ) floor(double_t x);
  309.  
  310. EXTERN_API_C( double_t ) rint(double_t x);
  311.  
  312. EXTERN_API_C( double_t ) nearbyint(double_t x);
  313.  
  314. EXTERN_API_C( long ) rinttol(double_t x);
  315.  
  316. EXTERN_API_C( double_t ) round(double_t x);
  317.  
  318. EXTERN_API_C( long ) roundtol(double_t round);
  319.  
  320. #if TARGET_CPU_68K
  321. EXTERN_API_C( int ) trunc(double_t x);
  322.  
  323. #else
  324. EXTERN_API_C( double_t ) trunc(double_t x);
  325.  
  326. #endif  /* TARGET_CPU_68K */
  327.  
  328.  
  329. /********************************************************************************
  330. *                                                                                 *
  331. *                            Remainder functions                                   *
  332. *                                                                                 *
  333. *     remainder        IEEE 754 floating point standard for remainder.                *
  334. *     remquo            SANE remainder.  It stores into 'quotient' the 7 low-order    *
  335. *                    bits of the integer quotient x/y, such that:                *
  336. *                        -127 <= quotient <= 127.                                 *
  337. *                                                                                 *
  338. ********************************************************************************/
  339. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  340.  
  341. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  342.  
  343. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  344.  
  345.  
  346.  
  347. /********************************************************************************
  348. *                                                                                 *
  349. *                             Auxiliary functions                               *
  350. *                                                                                 *
  351. *     copysign        Produces a value with the magnitude of its first argument    *
  352. *                      and sign of its second argument.  NOTE: the order of the     *
  353. *                      arguments matches the recommendation of the IEEE 754         *
  354. *                    floating point standard,  which is opposite from the SANE    *
  355. *                    copysign function.                                             *
  356. *                                                                                 *
  357. *     nan                The call 'nan("n-char-sequence")' returns a quiet NaN         *
  358. *                      with content indicated through tagp in the selected         *
  359. *                    data type format.                                              *
  360. *                                                                                *
  361. *     nextafter        Computes the next representable value after 'x' in the         *
  362. *                    direction of 'y'.  if x == y, then y is returned.            *
  363. *                                                                                 *
  364. ********************************************************************************/
  365. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  366.  
  367. EXTERN_API_C( long double ) nanl(const char *tagp);
  368.  
  369. EXTERN_API_C( double ) nan(const char *tagp);
  370.  
  371. EXTERN_API_C( float ) nanf(const char *tagp);
  372.  
  373. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  374.  
  375. EXTERN_API_C( double ) nextafterd(double x, double y);
  376.  
  377. EXTERN_API_C( float ) nextafterf(float x, float y);
  378.  
  379.  
  380.  
  381. /********************************************************************************
  382. *                                                                                 *
  383. *                              Inquiry macros                                   *
  384. *                                                                                 *
  385. *     fpclassify        Returns one of the FP_≈ values.                                *
  386. *     isnormal        Non-zero if and only if the argument x is normalized.          *
  387. *     isfinite        Non-zero if and only if the argument x is finite.             *
  388. *     isnan            Non-zero if and only if the argument x is a NaN.              *
  389. *     signbit            Non-zero if and only if the sign of the argument x is        *
  390. *                      negative.  This includes, NaNs, infinities and zeros.         *
  391. *                                                                                 *
  392. ********************************************************************************/
  393.  
  394. enum {
  395.     FP_SNAN                        = 0,                            /*      signaling NaN                         */
  396.     FP_QNAN                        = 1,                            /*      quiet NaN                             */
  397.     FP_INFINITE                    = 2,                            /*      + or - infinity                       */
  398.     FP_ZERO                        = 3,                            /*      + or - zero                           */
  399.     FP_NORMAL                    = 4,                            /*      all normal numbers                    */
  400.     FP_SUBNORMAL                = 5                                /*      denormal numbers                      */
  401. };
  402.  
  403.  
  404. #if defined(__MWERKS__) && defined(__cmath__)
  405. /* these macros were already defined in MSL's math.h */
  406. #else
  407. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  408.                               __fpclassify  ( x ) :                            \
  409.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  410.                               __fpclassifyd ( x ) :                            \
  411.                               __fpclassifyf ( x ) )
  412. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  413.                               __isnormal ( x ) :                               \
  414.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  415.                               __isnormald ( x ) :                              \
  416.                               __isnormalf ( x ) )
  417. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  418.                               __isfinite ( x ) :                               \
  419.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  420.                               __isfinited ( x ) :                              \
  421.                               __isfinitef ( x ) )
  422. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  423.                               __isnan ( x ) :                                  \
  424.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  425.                               __isnand ( x ) :                                 \
  426.                               __isnanf ( x ) )
  427. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  428.                               __signbit ( x ) :                                \
  429.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  430.                               __signbitd ( x ) :                               \
  431.                               __signbitf ( x ) )
  432. #endif  /* __MWERKS__ && __cmath__ */
  433.  
  434. EXTERN_API_C( long ) __fpclassify(long double x);
  435.  
  436. EXTERN_API_C( long ) __fpclassifyd(double x);
  437.  
  438. EXTERN_API_C( long ) __fpclassifyf(float x);
  439.  
  440. EXTERN_API_C( long ) __isnormal(long double x);
  441.  
  442. EXTERN_API_C( long ) __isnormald(double x);
  443.  
  444. EXTERN_API_C( long ) __isnormalf(float x);
  445.  
  446. EXTERN_API_C( long ) __isfinite(long double x);
  447.  
  448. EXTERN_API_C( long ) __isfinited(double x);
  449.  
  450. EXTERN_API_C( long ) __isfinitef(float x);
  451.  
  452. EXTERN_API_C( long ) __isnan(long double x);
  453.  
  454. EXTERN_API_C( long ) __isnand(double x);
  455.  
  456. EXTERN_API_C( long ) __isnanf(float x);
  457.  
  458. EXTERN_API_C( long ) __signbit(long double x);
  459.  
  460. EXTERN_API_C( long ) __signbitd(double x);
  461.  
  462. EXTERN_API_C( long ) __signbitf(float x);
  463.  
  464. EXTERN_API_C( double_t ) __inf(void );
  465.  
  466.  
  467.  
  468. /********************************************************************************
  469. *                                                                                 *
  470. *                      Max, Min and Positive Difference                         *
  471. *                                                                                 *
  472. *     fdim        Determines the 'positive difference' between its arguments:     *
  473. *                { x - y, if x > y }, { +0, if x <= y }.  If one argument is        *
  474. *                  NaN, then fdim returns that NaN.  if both arguments are NaNs,     *
  475. *                 then fdim returns the first argument.                            *
  476. *                                                                                 *
  477. *     fmax        Returns the maximum of the two arguments.  Corresponds to the    *
  478. *                max function in FORTRAN.  NaN arguments are treated as missing     *
  479. *                data.  If one argument is NaN and the other is a number, then     *
  480. *                the number is returned.  If both are NaNs then the first         *
  481. *                argument is returned.                                             *
  482. *                                                                                 *
  483. *     fmin        Returns the minimum of the two arguments.  Corresponds to the    *
  484. *                min function in FORTRAN.  NaN arguments are treated as missing     *
  485. *                data.  If one argument is NaN and the other is a number, then     *
  486. *                the number is returned.  If both are NaNs then the first         *
  487. *                argument is returned.                                            *
  488. *                                                                                 *
  489. ********************************************************************************/
  490. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  491.  
  492. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  493.  
  494. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  495.  
  496.  
  497.  
  498. /*******************************************************************************
  499. *                                Constants                                     *
  500. *******************************************************************************/
  501. extern const double_t pi;
  502.  
  503.  
  504. /********************************************************************************
  505. *                                                                                 *
  506. *                              Non NCEG extensions                                *
  507. *                                                                                 *
  508. ********************************************************************************/
  509. #ifndef __NOEXTENSIONS__
  510. /********************************************************************************
  511. *                                                                                 *
  512. *                              Financial functions                              *
  513. *                                                                                 *
  514. *     compound        Computes the compound interest factor "(1 + rate)^periods"    *
  515. *                      more accurately than the straightforward computation with     *
  516. *                    the Power function.  This is SANE's compound function.      *
  517. *                                                                                 *
  518. *     annuity            Computes the present value factor for an annuity             *
  519. *                      "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  520. *                    the straightforward computation with the Power function.     *
  521. *                    This is SANE's annuity function.                              *
  522. *                                                                                 *
  523. ********************************************************************************/
  524. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  525.  
  526. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  527.  
  528.  
  529.  
  530. /********************************************************************************
  531. *                                                                                 *
  532. *                              Random function                                  *
  533. *                                                                                 *
  534. *     randomx            A pseudorandom number generator.  It uses the iteration:    *
  535. *                                (7^5*x)mod(2^31-1)                                *
  536. *                                                                                 *
  537. ********************************************************************************/
  538. EXTERN_API_C( double_t ) randomx(double_t *x);
  539.  
  540.  
  541.  
  542. /*******************************************************************************
  543. *                              Relational operator                             *
  544. *******************************************************************************/
  545. /*      relational operator      */
  546. typedef short                             relop;
  547.  
  548. enum {
  549.     GREATERTHAN                    = 0,
  550.     LESSTHAN                    = 1,
  551.     EQUALTO                        = 2,
  552.     UNORDERED                    = 3
  553. };
  554.  
  555. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  556.  
  557.  
  558.  
  559. /********************************************************************************
  560. *                                                                                 *
  561. *                         Binary to decimal conversions                         *
  562. *                                                                                 *
  563. *     SIGDIGLEN    Significant decimal digits.                                        *
  564. *                                                                                 *
  565. *     decimal        A record which provides an intermediate unpacked form for        *
  566. *                programmers who wish to do their own parsing of numeric input     *
  567. *                or formatting of numeric output.                                  *
  568. *                                                                                 *
  569. *     decform        Controls each conversion to a decimal string.  The style field     *
  570. *                is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the     *
  571. *                value of the field digits is the number of significant digits.  *
  572. *                  If FIXEDDECIMAL value of the field digits is the number of        *
  573. *                digits to the right of the decimal point.                         *
  574. *                                                                                 *
  575. *     num2dec        Converts a double_t to a decimal record    using a decform.        *
  576. *     dec2num        Converts a decimal record d to a double_t value.                *
  577. *     dec2str        Converts a decform and decimal to a string using a decform.        *
  578. *     str2dec        Converts a string to a decimal struct.                            *
  579. *     dec2d        Similar to dec2num except a double is returned (68k only).        *
  580. *     dec2f        Similar to dec2num except a float is returned.                    *
  581. *     dec2s        Similar to dec2num except a short is returned.                    *
  582. *     dec2l        Similar to dec2num except a long is returned.                     *
  583. *                                                                                 *
  584. ********************************************************************************/
  585. #if    TARGET_CPU_PPC
  586.     #define SIGDIGLEN      36              
  587. #elif TARGET_CPU_68K
  588.     #define SIGDIGLEN      20
  589. #endif
  590. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  591. #define      FLOATDECIMAL   ((char)(0))
  592. #define      FIXEDDECIMAL   ((char)(1))
  593.  
  594.  
  595. struct decimal {
  596.     char                             sgn;                        /* sign 0 for +, 1 for - */
  597.     char                             unused;
  598.     short                             exp;                        /* decimal exponent */
  599.     struct {
  600.         unsigned char                     length;
  601.         unsigned char                     text[SIGDIGLEN];        /* significant digits */
  602.         unsigned char                     unused;
  603.     }                                 sig;
  604. };
  605. typedef struct decimal decimal;
  606.  
  607. struct decform {
  608.     char                             style;                        /*  FLOATDECIMAL or FIXEDDECIMAL */
  609.     char                             unused;
  610.     short                             digits;
  611. };
  612. typedef struct decform decform;
  613.  
  614. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  615.  
  616. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  617.  
  618. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  619.  
  620. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  621.  
  622. #if TARGET_CPU_68K
  623. EXTERN_API_C( double ) dec2d(const decimal *d);
  624.  
  625. #endif  /* TARGET_CPU_68K */
  626.  
  627. EXTERN_API_C( float ) dec2f(const decimal *d);
  628.  
  629. EXTERN_API_C( short ) dec2s(const decimal *d);
  630.  
  631. EXTERN_API_C( long ) dec2l(const decimal *d);
  632.  
  633.  
  634.  
  635.  
  636. /********************************************************************************
  637. *                                                                                 *
  638. *                         68k-only Transfer Function Prototypes                 *
  639. *                                                                                 *
  640. ********************************************************************************/
  641. #if TARGET_CPU_68K
  642. #if TARGET_RT_MAC_68881
  643. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  644.  
  645. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  646.  
  647. #else
  648. EXTERN_API_C( void ) x96tox80(const extended96 *x96, extended80 *x);
  649.  
  650. EXTERN_API_C( void ) x80tox96(const extended80 *x, extended96 *x96);
  651.  
  652. #endif  /* TARGET_RT_MAC_68881 */
  653.  
  654. #endif  /* TARGET_CPU_68K */
  655.  
  656. #endif  /* !defined(__NOEXTENSIONS__) */
  657.  
  658. /********************************************************************************
  659. *                                                                                 *
  660. *                         PowerPC-only Function Prototypes                         *
  661. *                                                                                 *
  662. ********************************************************************************/
  663.  
  664. #if TARGET_CPU_PPC
  665. EXTERN_API_C( long double ) cosl(long double x);
  666.  
  667. EXTERN_API_C( long double ) sinl(long double x);
  668.  
  669. EXTERN_API_C( long double ) tanl(long double x);
  670.  
  671. EXTERN_API_C( long double ) acosl(long double x);
  672.  
  673. EXTERN_API_C( long double ) asinl(long double x);
  674.  
  675. EXTERN_API_C( long double ) atanl(long double x);
  676.  
  677. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  678.  
  679. EXTERN_API_C( long double ) coshl(long double x);
  680.  
  681. EXTERN_API_C( long double ) sinhl(long double x);
  682.  
  683. EXTERN_API_C( long double ) tanhl(long double x);
  684.  
  685. EXTERN_API_C( long double ) acoshl(long double x);
  686.  
  687. EXTERN_API_C( long double ) asinhl(long double x);
  688.  
  689. EXTERN_API_C( long double ) atanhl(long double x);
  690.  
  691. EXTERN_API_C( long double ) expl(long double x);
  692.  
  693. EXTERN_API_C( long double ) expm1l(long double x);
  694.  
  695. EXTERN_API_C( long double ) exp2l(long double x);
  696.  
  697. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  698.  
  699. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  700.  
  701. EXTERN_API_C( long double ) logl(long double x);
  702.  
  703. EXTERN_API_C( long double ) log1pl(long double x);
  704.  
  705. EXTERN_API_C( long double ) log10l(long double x);
  706.  
  707. EXTERN_API_C( long double ) log2l(long double x);
  708.  
  709. EXTERN_API_C( long double ) logbl(long double x);
  710.  
  711. EXTERN_API_C( long double ) scalbl(long double x, long n);
  712.  
  713. EXTERN_API_C( long double ) fabsl(long double x);
  714.  
  715. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  716.  
  717. EXTERN_API_C( long double ) powl(long double x, long double y);
  718.  
  719. EXTERN_API_C( long double ) sqrtl(long double x);
  720.  
  721. EXTERN_API_C( long double ) erfl(long double x);
  722.  
  723. EXTERN_API_C( long double ) erfcl(long double x);
  724.  
  725. EXTERN_API_C( long double ) gammal(long double x);
  726.  
  727. EXTERN_API_C( long double ) lgammal(long double x);
  728.  
  729. EXTERN_API_C( long double ) ceill(long double x);
  730.  
  731. EXTERN_API_C( long double ) floorl(long double x);
  732.  
  733. EXTERN_API_C( long double ) rintl(long double x);
  734.  
  735. EXTERN_API_C( long double ) nearbyintl(long double x);
  736.  
  737. EXTERN_API_C( long ) rinttoll(long double x);
  738.  
  739. EXTERN_API_C( long double ) roundl(long double x);
  740.  
  741. EXTERN_API_C( long ) roundtoll(long double round);
  742.  
  743. EXTERN_API_C( long double ) truncl(long double x);
  744.  
  745. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  746.  
  747. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  748.  
  749. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  750.  
  751. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  752.  
  753. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  754.  
  755. EXTERN_API_C( long double ) fminl(long double x, long double y);
  756.  
  757.  
  758. #ifndef __NOEXTENSIONS__
  759. EXTERN_API_C( relop ) relationl(long double x, long double y);
  760.  
  761. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  762.  
  763. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  764.  
  765. /*    
  766.     MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  767.     be used to directly transform 68k 80-bit extended data types to double
  768.     and back for PowerPC based machines without using the functions
  769.     x80told or ldtox80.  Double rounding may occur. 
  770. */
  771. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  772.  
  773. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  774.  
  775. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  776.  
  777. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  778.  
  779. #endif  /* !defined(__NOEXTENSIONS__) */
  780.  
  781. #endif  /* TARGET_CPU_PPC */
  782.  
  783. #else
  784. /*
  785.     Non-Mac platforms may have long doubles.
  786. */
  787. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  788.  
  789. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  790.  
  791. #endif  /* TARGET_OS_MAC */
  792.  
  793.  
  794. #if PRAGMA_STRUCT_ALIGN
  795.     #pragma options align=reset
  796. #elif PRAGMA_STRUCT_PACKPUSH
  797.     #pragma pack(pop)
  798. #elif PRAGMA_STRUCT_PACK
  799.     #pragma pack()
  800. #endif
  801.  
  802. #ifdef PRAGMA_IMPORT_OFF
  803. #pragma import off
  804. #elif PRAGMA_IMPORT
  805. #pragma import reset
  806. #endif
  807.  
  808. #ifdef __cplusplus
  809. }
  810. #endif
  811.  
  812. #endif /* __FP__ */
  813.  
  814.